{extend name="public/base" /}
{block name='body'}
<div class="layui-container">
    <div class="fly-panel">
        <div class="fly-panel-title fly-filter">
            <a>{$q} 的搜索结果</a>
        </div>


        <ul class="fly-list" id="sw-res-searchs-list">
            <div class="sw-loading-icon">
                <img src="__PUBLIC__/uploads/default/lading_radius.gif" alt="">
            </div>

        </ul>
    </div>
</div>

{/block}
{block name='script'}
<script>
    function dataToHtml(resAttr) {
        return resTpl = ` <li>
                        <a href="{:url('home/user/userdetail')}?guid=${resAttr.userguid}"
                           class="fly-avatar">
                            <img src="__PUBLIC__/${resAttr.cover}"
                                 alt=".">
                        </a>
                        <h2>
                            <a class="layui-badge">${resAttr.catname}</a>
                            <a href="{:url('home/index/detail')}?guid=${resAttr.resguid}">${resAttr.title}</a>
                        </h2>
                        <div class="fly-list-info">
                            <a href="{:url('home/user/userdetail')}?guid=${resAttr.userguid}" link>
                                <cite>${resAttr.name}</cite>
                                <i class="layui-badge fly-badge-vip">${resAttr.level}</i>
                            </a>
                            <span>${resAttr.createTime}</span>

                            <span title="所需金币"><img src="__IMG__/goldIcon.png"
                                                    class="sw-money-icon">${resAttr.price}</span>
                            <span class="layui-badge fly-badge-accept layui-hide-xs"
                                  title="下载量">${resAttr.downloads}</span>
                            <span class="fly-list-nums">
                <i class="iconfont icon-pinglun1" title="评论"></i>${resAttr.comments}
              </span>
                        </div>
                        <div class="fly-list-badge">
                            <!--
                            <span class="layui-badge layui-bg-black">置顶</span>
                            <span class="layui-badge layui-bg-red">精帖</span>
                            -->
                        </div>
                    </li>`;
    }

    layui.config({
        base: "__JS__/"
    }).use(['jquery'], function () {
        let $ = layui.jquery;
        let api = "{:url('index/searchAPI')}?q={$q}";
        $.get(api, function (res) {
            let resData = '';
            $.each(res.data, function (index, obj) {
                resData += dataToHtml(obj);
            });
            if (resData) {

                $('#sw-res-searchs-list').html(resData);
            } else {
                //暂无数据模板
                var emptyTpl = `<div class="layui-container fly-marginTop ">
    <div class="fly-panel">
        <div class="fly-none" style="
        min-height: 419px;
    text-align: center;
    padding-top: 101px;
    color: #999;">
            <h2><img src="__PUBLIC__/uploads/default/empty.jpg" alt=""></h2>
            <p>暂无数据,请换个关键词试试</p>
        </div>
    </div>
</div>`;
                $('#sw-res-searchs-list').html(emptyTpl);

            }
        });
    })
</script>
{/block}